/**
 * cookie存储
 * @param {string} key 键
 * @param {Object} val 值
 * @param {Number} time 时间，默认10s
 */
function setcookie(key,val,time=10){
    if(typeof val == 'object') val=JSON.stringify(val)
    const d=new Date
    d.setTime(d.getTime()-1000*60*60*8+time*1000)
    document.cookie=`${key}=${val}; expires=${d}`
}

/**
 * COOKIE获取
 * @param {String} key 键
 * @returns String
 */
function getcookie(key){
    let arr = document.cookie.split('; ')
    arr.forEach(item=>{
        if(!item) return
        let tempArr = item.split('=')
        if(tempArr[0]==key) return tempArr[1]
    })
}

/**
 * 
 * @param {String} key 键
 * @returns undefined
 */
function removecookie(key){
    setcookie(key,null,-1)
}